package 富婆梦.第一阶段.第七周IO流;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @ProjectName: java-learning
 * @Package: 富婆梦.第一阶段.第七周
 * @ClassName: LockingMappesFiles
 * @Author: hemengjin
 * @Description: 两个线程，分别枷锁文件不同部分
 * @Date:2021/9/12 23:36
 * @Version: 1.0
 */
public class LockingMappesFiles {
    private static final int LENGHT = 0x8FFFFFF;
    static FileChannel fc;

    public static void main(String[] args) throws Exception{
        fc = new RandomAccessFile("text.dat","rw").getChannel();
        MappedByteBuffer out = fc.map(FileChannel.MapMode.READ_WRITE,0,LENGHT);
        for (int i=0;i<LENGHT;i++){
            out.put((byte)'x');
        }
        //new LockAndModify(out,0,0+LENGHT/3);
    }
}
